package com.ck.dp.subject;

import java.util.ArrayList;
import java.util.List;

import com.ck.dp.observer.Observer;

public class WeatherData implements Subject {
	
	private List<Observer> observers;
	/**
	 * 温度
	 */
	private float temperature;//温度
	/**
	 * 湿度
	 */
    private float humidity;//湿度
    /**
     * 气压
     */
    private float pressure;//气压
	
    /**
     * 未来几天的温度
     */
    private List<Float> forecastTemperatures;
    
    
	public WeatherData() {
		this.observers = new ArrayList<Observer>();
	}

	public void registerObserver(Observer observer) {
		this.observers.add(observer);
	}

	public void removeObserver(Observer observer) {
		this.observers.remove(observer);
	}

	public void notifyObserver() {
		for (Observer observer : observers) {
			 observer.update();
		}
	}
	
	public void measurementsChanged() {
		notifyObserver();
	}
	
	public  void setMeasurements(float temperature, float humidity, 
		    float pressure, List<Float> forecastTemperatures) {
		this.temperature = temperature;
        this.humidity = humidity;
        this.pressure = pressure;
        this.forecastTemperatures = forecastTemperatures;
        measurementsChanged();
	}

	/**
	 * @return the temperature
	 */
	public float getTemperature() {
		return temperature;
	}

	/**
	 * @return the humidity
	 */
	public float getHumidity() {
		return humidity;
	}

	/**
	 * @return the pressure
	 */
	public float getPressure() {
		return pressure;
	}

	/**
	 * @return the forecastTemperatures
	 */
	public List<Float> getForecastTemperatures() {
		return forecastTemperatures;
	}
	
	

}
